home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: wbporter@aol.com (Wbporter)
- Newsgroups: comp.lang.c
- Subject: Re: 8 Queens prog help
- Date: 20 Apr 1996 10:41:19 -0400
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4lat2f$pk4@newsbf02.news.aol.com>
- References: <4l87ud$73u@solutions.solon.com>
- NNTP-Posting-Host: newsbf02.mail.aol.com
- X-Newsreader: AOL Offline Reader
-
- >Need some C help this week. I'm currently working on a program
- >called "Eight Queens". Basically, I have to place 8 queen chess
- >pieces on an 8x8 chess board without them checking one another.
-
- You don't need a 2-d array for the board, but four linear arrays would
- come in
- handy, defined globally so that all recursive searches can use them. One
- would use
- the file as subscript to hold the rank you are working on. The other
- three would
- hold zeros until a queen had been placed. The subscripts would be (in
- turn)
- the rank, SUM of rank and file, and DIFFERENCE of rank and file (plus
- constant
- to prevent a negative value). If you don't find a 1 at any of those array
- locations
- after calculating the subscripts, place 1 there and either do the next
- recursion
- (next file) or display a solution. If you successfully place a queen at
- any point,
- zero the appropriate place in each array before moving on.
-
- The sum and difference arrays will handle conflicts on the diagonals and
- the rank
- array is self explanatory. The fact you can only do one subscript at a
- time takes
- care of conflicts on the file. Hope this helps.
-
-